
module.exports = (app) => { 
  const DataTypes = app.Sequelize;

  const Deviceinfo = app.model.define('t_prideviceinfo', {
    pdi_index: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true
    },
    pdi_name: {
      type: DataTypes.STRING(255),
      allowNull: false,
      defaultValue: ""
    },
    pdi_code: {
      type: DataTypes.STRING(255),
      allowNull: false,
      defaultValue: ""
    },
    dpt_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    pdi_updatetime: {
      type: DataTypes.DATE,
      allowNull: true
    },

    AreaId: {
      type: DataTypes.STRING(20),
      allowNull: true
    },

    Co_ID: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0
    },

    DragX: {
      type: DataTypes.STRING(50),
      allowNull: true,
      defaultValue: "0"
    },
    DragY: {
      type: DataTypes.STRING(50),
      allowNull: true,
      defaultValue: "0"
    },
    SubNum: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0
    },
    SubType: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0
    },
    pdi_local_en: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0
    },
    pdi_uart_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 1
    },
    pdi_uart_pro: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 1000
    },
    pdi_uart_dev_addr: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 1
    }
  }, {
    tableName: 't_prideviceinfo',
    timestamps: false,
    underscored: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "pdi_index" },
        ]
      },
      {
        name: "pdi_index",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "pdi_index" },
        ]
      },
    ]
  });


  Deviceinfo.associate = function() {
    app.model.TPrideviceinfo.hasOne(app.model.TDevicetype, { as: 'devicetype', sourceKey: 'dpt_id', foreignKey: 'dt_typeid' });
  };

  // Deviceinfo.associate = function() {
  //   app.model.TPrideviceinfo.hasOne(app.model.TSubdevicetype, { as: 'stype', sourceKey: 'SubType', foreignKey: 'ts_typeid' });
  // };

  return Deviceinfo;
};
